<?php
require_once __DIR__ . "/include_common.php";
//创建协程
go(function () {
    $pool = new \Core\init\PdoPool();
    $pool->init();
    //创建10个协程
    for ($i = 1; $i <= 8; $i++) {
        go(function () use ($pool, $i) {
            /**@var $pool \Core\init\PdoPool* */
            $pdoObject = $pool->getConnect();
            defer(function () use ($pool, $pdoObject) {
                $pool->close($pdoObject);
            });
            /**@var $pdo PDO* */
            $pdo = $pdoObject->db;
            $stat = $pdo->query("select sleep(5)");
            $stat->setFetchMode(PDO::FETCH_ASSOC);
            $rows = $stat->fetchAll();
            var_dump($rows);

        });
    }
    //创建10个协程
    for ($i = 1; $i <= 2; $i++) {
        go(function () use ($pool, $i) {
            /**@var $pool \Core\init\PdoPool* */
            $pdoObject = $pool->getConnect();
            defer(function () use ($pool, $pdoObject) {
                $pool->close($pdoObject);
            });
            /**@var $pdo PDO* */
            $pdo = $pdoObject->db;
            $stat = $pdo->query("select $i");
            $stat->setFetchMode(PDO::FETCH_ASSOC);
            $rows = $stat->fetchAll();
            var_dump($rows);
        });
    }
    while (true) {
        \Swoole\Coroutine::sleep(1);
    }
});
